<?php
defined("_VALID_ACCESS") || die('Direct access forbidden');
class SCTV_MaintenanceChangeRequestCommon extends ModuleCommon {
    public static function menu() { 
        return array(__('SCTV') => array(
        	'__submenu__' => 1, __('BẢO TRÌ') => array(
    			'__submenu__' => 2, __('Maintenance Change Request') => array()
			)));
    }
	public static function display_status($record, $nolink, $desc) {
		$status = $record['status'];
		if($status == 1)
		{
			$rb_obj = Utils_RecordBrowser::$rb_obj;
			$select_status = $rb_obj->init_module('Utils_LeightboxPrompt');
			$form = $rb_obj->init_module('Libs_QuickForm');
        	$form->addElement('text', 'note', __('Note'), array('id'=>'note'));
			$select_status->add_option('close', __('Close'), null, $form);
			$rb_obj->display_module($select_status, array(__( 'Process'), array('status')));
			$vals = $select_status->export_values();
			if (isset($vals['params']['status']) && $vals['params']['status'] == $record['id'] && !isset($_REQUEST['__location']))
			{
				if($vals['option'] == 'close')
				{
					self::close_request($record['id'], $vals['form']['note']);
					location(array());	
				}				
			}
						
			$href = $select_status->get_href(array('status' => $record['id']));
			return '<a ' . $href . '>' . self::get_status_name($record['status']) . '</a>';
		}
		else
			return self::get_status_name($record['status']);
	}
	public static function close_request($id, $note)
	{
		Utils_RecordBrowserCommon::update_record('SCTV_MaintenanceChangeRequest', $id, array('status'=>0, 'result'=>$note));
	} 
	public static function QFfield_status(&$form, $field, $label, $mode, $default, $desc, $rb_obj){
		if ($mode=='add')
		{
			$form->addElement('select', $field, $label, array('1'=>__('Open')), array('id'=>$field));
            $form->setDefaults(array($field=>$default));
		}		
		elseif ($mode=='edit')
		{
			$form->addElement('select', $field, $label, array('1'=>__('Open'), '0'=>__('Closed')), array('id'=>$field));
            $form->setDefaults(array($field=>$default));
		}
		else
		{
        	$form->addElement('static', $field, $label, self::get_status_name($default));
        }
    }
	public static function get_status_name($status)
	{		
		return $status == 1?__('Open'):__('Closed');
	}
}

?>